<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>自定义对话框</title>
        <#include "/pubHeadStyle.html">
        <script src="${ctx}/extends/jquery.min.js" type="text/javascript"></script>
    </head>
    <body>
    <form class="layui-form" lay-filter="setFiled">
        <div style="position: relative;height: 100%;">
            <div class="ccpui-trees">
                <p class="isShowTree colorSwitch">
                    <span style="float: left;color: white">&nbsp;&nbsp;获取字段列表</span>
                </p>
                <table id="tableField" lay-filter="tableField"></table>
            </div>
            <script type="text/html" id="toolbarDemo">
                <div style="position: absolute;left: 246px;top: 305px;">
                    <button class="layui-btn layui-btn-sm" lay-event="getCheckData" type="button"><i
                            class="layui-icon layui-icon-right"></i></button>
                </div>
            </script>
            <div class="ccpui-coreContent" style="left:300px;">
                <p class="colorSwitch" style="width: 100%;height: 30px;line-height: 30px;">
                    <span style="float: left;color: white">&nbsp;&nbsp;字段设置</span>
                </p>
                <div class="layui-collapse" lay-accordion="">
                    <div class="layui-colla-item">
                        <h2 class="layui-colla-title">显示字段</h2>
                        <div class="layui-colla-content displayField">
                            <div class="listDisplayFields">
                                <table id="showField" lay-filter="showField"></table>
                            </div>
                            <div class="treeDisplayField">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">ID</label>
                                    <div class="layui-input-block" style="width: 440px;">
                                        <input type="text" id="treeId" autocomplete="off" class="layui-input treeField">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">父ID</label>
                                    <div class="layui-input-block" style="width: 440px;">
                                        <input type="text" id="pid" autocomplete="off" class="layui-input treeField">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">父ID初始值</label>
                                    <div class="layui-input-block" style="width: 440px;">
                                        <input type="text" id="pvalue" autocomplete="off" class="layui-input">
                                        <input type="checkbox" lay-skin="primary" id="isScript" title="脚本">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">显示名称 </label>
                                    <div class="layui-input-block" style="width: 440px;">
                                        <input type="text" id="displayName" autocomplete="off"
                                               class="layui-input treeField">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-colla-item">
                        <h2 class="layui-colla-title">条件字段</h2>
                        <div class="layui-colla-content condition" style="padding-top:0;height: 270px;overflow-y: auto">
                            <div class="layui-tab" lay-filter="layTable">
                                <ul class="layui-tab-title">
                                    <li class="layui-this">条件选择</li>
                                    <li>java脚本</li>
                                    <li>帮助</li>
                                </ul>
                                <div class="layui-tab-content">
                                    <div class="layui-tab-item conditionTab layui-show">
                                        <table id="selectCondition" lay-filter="selectCondition"></table>
                                    </div>
                                    <div class="layui-tab-item scriptInput">
                                        <div style="width: 100%;margin:10px 0" id="scriptField"></div>
                                        <textarea name="javaScript" id="javaScript" cols="90" rows="10"
                                                  style="resize:none"></textarea>
                                    </div>
                                    <div class="layui-tab-item">例：if(map.get("ACTDEFID")!=null)</br>
                                        return " and ACTDEFID like '%"+map.get("ACTDEFID")+"%'" ;</br>
                                        其中的map为系统所封装的一个参数</br>
                                        在脚本中使用map.get("ACTDEFID")可以获取表单提交时所携带的ACTDEFID参数值，脚本应拼接并返回任意的可执行的sql语句
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-colla-item">
                        <h2 class="layui-colla-title">返回字段</h2>
                        <div class="layui-colla-content return">
                            <table id="returnField" lay-filter="returnField"></table>
                        </div>
                    </div>
                    <div class="layui-colla-item">
                        <h2 class="layui-colla-title">排序字段</h2>
                        <div class="layui-colla-content sort">
                            <div id="sortCheck">
                                <table id="sortField" lay-filter="sortField"></table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div style="position: absolute;top:508px;left:44%">
                <button class="layui-btn" type="button" lay-submit="" lay-filter="save">保存</button>
                <button class="layui-btn layui-btn-danger cancel">取消</button>
            </div>
        </div>
    </form>
    <script type="text/html" id="manageBar">
        <a class="layui-btn layui-btn-xs" lay-event="moveUp">上移</a>
        <a class="layui-btn layui-btn-xs" lay-event="moveDown">下移</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
    <script type="text/html" id="selectType">
        {{#  if(d.dbType == 'number'){ }}
        <select name="selectValue" lay-filter="selectValue" id="{{d.field}}">
            <option value="=">等于</option>
            <option value=">=">大于等于</option>
            <option value=">">大于</option>
            <option value="<">小于</option>
            <option value="<=">小于等于</option>
        </select>
        {{#  } else if(d.dbType == 'varchar'){ }}
        <select name="selectValue" lay-filter="selectValue" id="{{d.field}}">
            <option value='='>等于</option>
            <option value='like'>LIKE</option>
            <option value='likeEnd'>LIKEEND</option>
            <option value="<=">小于等于</option>

        </select>
        {{#  } else if(d.dbType == 'date'){ }}
        <select name="selectValue" lay-filter="selectValue" id="{{d.field}}">
            <option value='='>等于</option>
            <option value='between'>Between</option>
            <option value='>='>大于等于</option>
            <option value='<='>小于等于</option>
        </select>
        {{#  } }}
    </script>
    <script type="text/html" id="DefaultSelect">
        <div class="displayCol">
            <select class="layui-yonyou-select rightSelect" lay-filter="valueType" name="rightSelect"
                    id="default{{d.field}}">
                {{# if('${showStyle}' === '0'){ }}
                <option value='1'>表单输入</option>
                {{# }}}
                <option value='4'>动态传入</option>
                <option value='2'>固定值</option>
                <option value='3'>脚本</option>
            </select>
        </div>
        {{# if('${showStyle}' === '0'){ }}
        <div class="userType" id="selector">
            <select class="layui-yonyou-select" lay-filter="userType" name="userType">
                <option value='1'>单行文本框</option>
                <option value='4'>人员选择器(单选)</option>
                <option value='17'>角色选择器(单选)</option>
                <option value='18'>组织选择器(单选)</option>
                <option value='19'>岗位选择器(单选)</option>
                <option value='0'>自定义对话框</option>
            </select>
        </div>
        {{# }}}
        {{# if('${showStyle}' === '0'){ }}
        <div class="dataType" style="display:none">
            <select name="formDialog" class="formDialog" lay-filter="formDialog">
                <option value=""></option>
            </select>
            <select name="listDialog" class="listDialog" lay-filter="listDialog">
                <option value=""></option>
            </select>
        </div>
        {{# }}}
    </script>
    <script>
        layui.config({
            base: serverPath.formPath + staticPath.formPath //静态资源所在路径
        }).extend({
            index: 'index' //主入口模块
        }).use(['index', 'table', 'layer', 'jquery', 'form', 'element', 'setter', 'commons'], function () {
            var table = layui.table, setter = layui.setter, $ = layui.jquery, layer = layui.layer,
                element = layui.element, form = layui.form, commons = layui.commons;
            var formDialogId = '${formDialogId}';
            var dsName = '${dsName}';
            var isTable = '${isTable}';
            var objectName = '${objectName}';
            var showStyle = '${showStyle}';
            var tab = 0;//判断tab 选项卡 哪个选中 默认0 条件选择
            if (formDialogId === "") {
                var array = [];
                loadConditionField(array);
                loadSortField(array);
                loadReturnField(array);
                //回显显示字段
                loadDisplayField(array);
            }
            var curField;
            $("input.treeField").focus(function () {
                curField = $(this);
            });

            //设置列后台接口
            $.ajax({
                url: serverPath.formPath + setter.formLinkPath + "formQuery/setCol",
                dataType: 'json',
                type: "post",
                data: {
                    "formQueryId": formDialogId,
                    "dsName": dsName,
                    "isTable": isTable,
                    "objectName": objectName,
                    "type": 2
                },
                success: function (result) {
                    if (commons._filterRecord(result)) {
                        //加载左侧表格数据
                        loadTable(result.data.tableModel.columnList);
                    }
                }
            });


            //父页面数据回显
            var allData = parent.window.getArea();
            if (allData !== "") {
                var res = JSON.parse(allData);

                var judge = true;
                if (res.conditionfield.length > 0) {
                    if (res.conditionfield[0].defaultType === "5") {
                        judge = false;
                    }
                }
                if (judge) {
                    //回显条件选择
                    loadConditionField(res.conditionfield);
                } else {
                    //回显java脚本
                    tab = 1;
                    $.each(res.conditionfield, function (i, item) {
                        $("#scriptField").append('<a class="layui-btn layui-btn-xs" style="padding-right:15px;" onclick="addField(this)" comment="' + item.comment + '">' + item.field + '</a>' +
                            '<i style="color: red;position: relative;top:-2px;right:12px;width: 8px;height: 8px;" onclick="deletePrevious(this)">X</i>');
                    });
                    $("#javaScript").val(res.conditionfield[0].defaultValue);
                    $('ul li').each(function (i, item) {
                        $(item).attr("class", "");
                        if ($.trim($(item).text()) === "java脚本") {
                            $(item).attr("class", "layui-this");
                            $(".scriptInput").attr("class", "layui-tab-item scriptInput layui-show");
                            $(".conditionTab").attr("class", "layui-tab-item conditionTab");
                        }
                    });
                    loadConditionField(new Array());
                }
                //回显排序字段
                loadSortField(res.sortfield);
                //回显返回字段
                loadReturnField(res.resultfield);
                //回显显示字段
                loadDisplayField(res.displayfield);
            }

            //关闭弹窗
            $(".cancel").on('click', function () {
                parent.layer.close(parent.layer.getFrameIndex(window.name))
            });
            //初始化面板
            element.init();

            var selectorHtml = "<div style='margin-top:10px;' class='selectorDiv'>";
            var userButton = "<input type='text'class='layui-input' style='float: left;height: 30px;margin-right:5px;width: 150px'></div>";
            var appendHtml = selectorHtml + userButton;
            //下拉选项请求数据回显
            var allDialogReturn;

            function selectData() {
                $.ajax({
                    url: serverPath.formPath + setter.formLinkPath + 'formDialog/list',
                    type: "GET",
                    contentType: 'application/json',
                    dataType: 'json',
                    page: false,
                    async: false,
                    success: function (data) {
                        allDialogReturn = data.data;
                        $(".formDialog").html("");
                        $(".formDialog").append("<option value=''>请选择对话框</option>");
                        $.each(allDialogReturn, function (index, objVal) {
                            $(".formDialog").append("<option value=" + objVal.alias + ">" + objVal.name + "</option>");
                        });
                        form.render();
                    }
                });
            }

            //监听自定义对话框选项
            form.on('select(formDialog)', function (data) {
                var obj = $(this);
                $.each(allDialogReturn, function (index, objVal) {
                    if (data.value == objVal.alias) {
                        var resultArray = JSON.parse(objVal.resultfield);
                        obj.parent().parent().next().html("");
                        obj.parent().parent().next().append("<option value=''>请选择返回值</option>");
                        $.each(resultArray, function (index, resultVal) {
                            obj.parent().parent().next().append("<option value=" + resultVal.field + ">" + resultVal.comment + "</option>");
                        });
                    }
                });
                form.render("select");
            });

            form.on('select(valueType)', function (data) {
                var fieldName = $(this).parents(".layui-table-cell").parent().prev().prev().prev().prev().children().text();
                var scriptObj = 'script_' + fieldName;
                var scriptButton = "<textarea class='layui-input' style='float: left;height: 70px;width: 150px;margin-right:5px;' id='" + scriptObj + "'></textarea><button type='button' class='layui-btn layui-btn-xs selectScript'>选择</button></div>";
                var newAppendHtml = selectorHtml + scriptButton;
                if (data.value === '1') {
                    $(this).parent().parent().parent().find(".selectorDiv").remove();
                    $(this).parent().parent().parent().parent().find(".userType").css("display", "block");
                    if ($(this).parent().parent().parent().next().find("select").val() == 0) {
                        $(this).parent().parent().parent().parent().find(".dataType").css('display', "block");
                    }
                }
                else if (data.value === '2') {
                    $(this).parent().parent().parent().find(".selectorDiv").remove();
                    $(this).parent().parent().parent().parent().find(".userType").css('display', "none");
                    $(this).parent().parent().parent().parent().find(".dataType").css('display', "none");
                    $(this).parent().parent().parent().append(appendHtml);
                }
                else if (data.value === '3') {
                    $(this).parent().parent().parent().find(".selectorDiv").remove();
                    $(this).parent().parent().parent().parent().find(".userType").css('display', "none");
                    $(this).parent().parent().parent().parent().find(".dataType").css('display', "none");
                    $(this).parent().parent().parent().append(newAppendHtml);
                } else if (data.value === '4') {
                    $(this).parent().parent().parent().find(".selectorDiv").remove();
                    $(this).parent().parent().parent().parent().find(".userType").css('display', "none");
                    $(this).parent().parent().parent().parent().find(".dataType").css('display', "none");
                }
            });
            form.on('select(userType)', function (data) {
                if (data.value == 0) {
                    $(this).parent().parent().parent().parent().find(".dataType").css('display', "block");
                } else {
                    $(this).parent().parent().parent().parent().find(".dataType").css('display', "none");
                }
            });
            element.on('tab(layTable)', function (data) {
                if (data.index === 0) {//条件选择
                    tab = 0;
                } else if (data.index === 1) {//java脚本
                    tab = 1;
                }
            });
            //监听提交
            form.on('submit(save)', function (data) {
                //条件字段数据ConditionField
                var conditionArray = [];
                if (tab === 0) {
                    var conditionFieldArray = $("#selectCondition").next().find("tbody").children();
                    for (var k = 0; k < conditionFieldArray.length; k++) {
                        var jsonCondition = {};
                        jsonCondition.field = $($(conditionFieldArray[k]).find("td").get(0)).find("div").html();
                        jsonCondition.comment = $($(conditionFieldArray[k]).find("td").get(2)).find("div").html();
                        jsonCondition.condition = $($(conditionFieldArray[k]).find("td").get(1)).find("select").find("option:selected").val();
                        jsonCondition.dbType = $($(conditionFieldArray[k]).find("td").get(3)).find("div").html();
                        jsonCondition.defaultType = $($(conditionFieldArray[k]).find("td").get(4)).find("select").find("option:selected").val();
                        if (jsonCondition.defaultType === "2") {
                            jsonCondition.defaultValue = $($(conditionFieldArray[k]).find("td").get(4)).find("select").next().next().find("input").val();
                        } else if (jsonCondition.defaultType === "3") {
                            jsonCondition.defaultValue = $($(conditionFieldArray[k]).find("td").get(4)).find("select").next().next().find("textarea").val();
                        } else {
                            jsonCondition.defaultValue = "";
                        }
                        if (jsonCondition.defaultType === "1" && jsonCondition.dbType != 'date') {
                            jsonCondition.paraCt = $($(conditionFieldArray[k]).find("td").get(4)).find("select[name=userType]").val();
                            if (jsonCondition.paraCt === "0") {
                                jsonCondition.dialog = $($(conditionFieldArray[k]).find("td").get(4)).find("select[name=formDialog]").val();
                                jsonCondition.param = $($(conditionFieldArray[k]).find("td").get(4)).find("select[name=listDialog]").val();
                            }
                        }
                        conditionArray.push(jsonCondition);
                    }
                } else {
                    var javaScript = $("#javaScript").val();
                    var scriptField = $("#scriptField").find("a");
                    for (var h = 0; h < scriptField.length; h++) {
                        var jsonJavaScript = {};
                        jsonJavaScript.field = $(scriptField[h]).text();
                        jsonJavaScript.comment = $(scriptField[h]).attr("comment");
                        jsonJavaScript.defaultType = "5";
                        jsonJavaScript.condition = "";
                        jsonJavaScript.dbType = "";
                        jsonJavaScript.defaultValue = javaScript;
                        conditionArray.push(jsonJavaScript);
                    }
                    if (scriptField.length === 0) {
                        var jsonScript = {};
                        jsonScript.field = "";
                        jsonScript.comment = "";
                        jsonScript.defaultType = "5";
                        jsonScript.condition = "";
                        jsonScript.dbType = "";
                        jsonScript.defaultValue = javaScript;
                        conditionArray.push(jsonScript);
                    }
                }
                //返回字段数据ReturnField
                var returnFieldArray = $("#returnField").next().find("tbody").children();
                var returnArray = getDisplayOrResultField(returnFieldArray);
                if (returnArray.length === 0) {
                    parent.layer.alert("请选择返回字段!");
                    return false;
                }
                //显示字段
                var displayField = $("#showField").next().find("tbody").children();
                var displayArray = getDisplayOrResultField(displayField);
                if (showStyle == 1) { //树形
                    displayArray = getDisplayTreeField();
                }
                if (displayArray.length === 0) {
                    parent.layer.alert("请选择显示字段!");
                    return false;
                }
                //排序字段数据SortField
                var sortFieldArray = $("#sortField").next().find("tbody").children();
                var sortArray = [];
                for (var j = 0; j < sortFieldArray.length; j++) {
                    var jsonSort = {};
                    jsonSort.field = $($(sortFieldArray[j]).find("td").get(0)).find("div").html();
                    if ($($(sortFieldArray[j]).find("td").get(1)).find("input[type='checkbox']").prop("checked")) {
                        jsonSort.comment = "ASC";
                    } else {
                        jsonSort.comment = "DESC";
                    }
                    sortArray.push(jsonSort);
                }
                parent.window.addSetCol(conditionArray, returnArray, sortArray, displayArray);
                parent.layer.close(parent.layer.getFrameIndex(window.name));
            });
            //脚本选择弹窗
            $(document).on('click', ".selectScript", function () {
                var areaId = $(this).prev().attr("id");
                parent.layer.open({
                    type: 2,
                    area: ["800px", "650px"],
                    title: ['脚本选择'],
                    content: serverPath.formPath + setter.formLinkPath + "table/view/script?param=1&parentName=" + window.name + "&scriptObj=" + areaId
                });
            });

            //获取树形对话框的显示字段
            function getDisplayTreeField() {
                var displayTree = {"id": "", "pid": "", "displayName": "", "pvalue": "", "isScript": ""};
                displayTree.id = $("#treeId").val();
                displayTree.pid = $("#pid").val();
                displayTree.pvalue = $("#pvalue").val();
                displayTree.displayName = $("#displayName").val();
                displayTree.isScript = "false";
                if ($("#isScript")[0].checked) {
                    displayTree.isScript = "true";
                }
                return displayTree;
            }

            //获取显示字段和返回字段数据
            function getDisplayOrResultField(obj) {
                var returnArray = [];
                for (var i = 0; i < obj.length; i++) {
                    var jsonReturn = {};
                    jsonReturn.field = $($(obj[i]).find("td").get(0)).find("div").html();
                    jsonReturn.comment = $($(obj[i]).find("td").get(1)).find("div").html();
                    returnArray.push(jsonReturn);
                }
                return returnArray;
            }

            //左侧表格数据
            function loadTable(data) {
                table.render({
                    elem: '#tableField'
                    , data: data
                    , title: '字段表'
                    , height: 'full-50'
                    , toolbar: '#toolbarDemo'
                    , defaultToolbar: []
                    , cols: [[
                        {type: 'checkbox'}
                        , {field: 'name', title: '字段', align: 'center'}
                        , {field: 'comment', title: '注释', align: 'center', edit: true}
                        , {field: 'columnType', title: '字段类型', align: 'center', hide: true}
                    ]]
                    , page: false
                    , limit: 1000
                });
            }

            // 穿梭到-返回和显示字段
            function returnAndDisplayField(result, obj) {
                for (var a = 0; a < result.length; a++) {
                    var returnArray = obj.next().find("tbody").children();
                    //如果条件选择中已经有了相同的则跳过
                    var judge = false;
                    for (var b = 0; b < returnArray.length; b++) {
                        if ($($(returnArray[b]).get(0)).find("div").html() === result[a].field) {
                            judge = true;
                        }
                    }
                    if (judge) {
                        continue;
                    }
                    obj.next().find("div .layui-none").remove();//去掉 无数据三个字
                    obj.next().find("tbody").append(
                        '<tr data-index="' + returnArray.length + '" class="">\n' +
                        '<td data-field="field" data-key="3-0-0" align="center" class="">\n' +
                        '<div class="layui-table-cell laytable-cell-3-0-0">' + result[a].field + '</div>\n' +
                        '</td>\n' +
                        '<td data-field="comment" data-key="3-0-1" align="center" class="">\n' +
                        '<div class="layui-table-cell laytable-cell-3-0-1">' + result[a].comment + '</div>\n' +
                        '</td>\n' +
                        '<td data-field="operation" data-key="3-0-2" align="center" data-off="true" class="">\n' +
                        '<div class="layui-table-cell laytable-cell-3-0-2"> \n' +
                        '<a class="layui-btn layui-btn-xs" lay-event="moveUp">上移</a> \n' +
                        '<a class="layui-btn layui-btn-xs" lay-event="moveDown">下移</a> \n' +
                        '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a> \n' +
                        '</div>\n' +
                        '</td>\n' +
                        '</tr>');
                    form.render();
                }
            }

            //穿梭框 向右按钮功能
            table.on('toolbar(tableField)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
                switch (obj.event) {
                    case 'getCheckData':
                        var result = checkStatus.data;  //获取选中行数据
                        for (var n = 0; n < result.length; n++) {
                            result[n].field = result[n].name;
                            result[n].dbType = result[n].columnType;
                        }
                        //穿梭到-显示字段
                        if ($(".displayField").hasClass("layui-show")) {
                            if (showStyle == 0) {
                                $('.treeDisplayField').hide();
                                returnAndDisplayField(result, $("#showField"));
                            } else if (showStyle == 1) {
                                if (curField == null || curField.length == 0) {
                                    parent.layer.alert("请选择右边的输入框!", '提示信息');
                                    return;
                                }
                                if (result.length == 0) {
                                    parent.layer.alert("请选择左边的字段!", '提示信息');
                                    return;
                                }
                                if (result.length > 1) {
                                    parent.layer.alert("只能选择一个左边的字段!", '提示信息');
                                    return;
                                }
                                curField.val(result[0].field);
                            }
                        }
                        //1.穿梭到-java脚本
                        if ($(".scriptInput").hasClass("layui-show")) {

                            var scriptField = $("#scriptField").find("a");
                            for (var i = 0; i < result.length; i++) {
                                //如果java脚本中已经有了相同的则跳过
                                var judge = false;
                                for (var h = 0; h < scriptField.length; h++) {
                                    if ($(scriptField[h]).text() === result[i].name) {
                                        judge = true;
                                    }
                                }
                                if (judge) {
                                    continue;
                                }
                                var name = result[i].name;
                                var comment = result[i].comment;
                                $("#scriptField").append('<a class="layui-btn layui-btn-xs" style="padding-right:15px;" onclick="addField(this)" comment="' + comment + '">' + name + '</a>' +
                                    '<i style="color: red;position: relative;top:-2px;right:12px;width: 8px;height: 8px;" onclick="deletePrevious(this)">X</i>');
                            }
                        }
                        //2.穿梭到-条件选择
                        if ($(".condition").hasClass("layui-show") && $(".conditionTab").hasClass("layui-show")) {
                            for (var a = 0; a < result.length; a++) {
                                var conditionArray = $("#selectCondition").next().find("tbody").children();
                                //如果条件选择中已经有了相同的则跳过
                                var judge = false;
                                for (var b = 0; b < conditionArray.length; b++) {
                                    if ($($(conditionArray[b]).get(0)).find("div").html() === result[a].field) {
                                        judge = true;
                                    }
                                }
                                if (judge) {
                                    continue;
                                }
                                $("#selectCondition").next().find("div .layui-none").remove();//去掉 无数据三个字


                                var option = '';
                                if (result[a].dbType === 'varchar' || result[a].dbType === 'text' || result[a].dbType === 'boolean') {
                                    option = '<option value="=">等于</option> \n' +
                                        '<option value="like">LIKE</option> \n' +
                                        '<option value="likeEnd">LIKEEND</option>';
                                } else if (result[a].dbType === 'number') {
                                    option = '<option value="=">等于</option>\n' +
                                        '<option value=">=">大于等于</option>\n' +
                                        '<option value=">">大于</option>\n' +
                                        '<option value="<">小于</option>\n' +
                                        '<option value="<=">小于等于</option>';
                                } else if (result[a].dbType === 'date') {
                                    option = '<option value="=">等于</option>\n' +
                                        '<option value="between">Between</option>\n' +
                                        '<option value=">=">大于等于</option>\n' +
                                        '<option value="<=">小于等于</option>';
                                }
                                var optionDD = '';
                                if (result[a].dbType === 'varchar' || result[a].dbType === 'text' || result[a].dbType === 'boolean') {
                                    optionDD = '<dd lay-value="=" class="layui-this">等于</dd>\n' +
                                        '<dd lay-value="like" class="">LIKE</dd>\n' +
                                        '<dd lay-value="likeEnd" class="">LIKEEND</dd>';
                                } else if (result[a].dbType === 'number') {
                                    optionDD = '<dd lay-value="=" class="layui-this">等于</dd>\n' +
                                        '<dd lay-value=">=" class="">大于等于</dd>\n' +
                                        '<dd lay-value=">" class="">大于</dd>\n' +
                                        '<dd lay-value="<" class="">小于</dd>\n' +
                                        '<dd lay-value="<=" class="">小于等于</dd>';
                                } else if (result[a].dbType === 'date') {
                                    optionDD = '<dd lay-value="=" class="layui-this">等于</dd>\n' +
                                        '<dd lay-value="between" class="">Between</dd>\n' +
                                        '<dd lay-value=">=" class="">大于等于</dd>\n' +
                                        '<dd lay-value="<=" class="">小于等于</dd>';
                                }

                                if (showStyle === '0') {
                                    $("#selectCondition").next().find("tbody").append(
                                        '<tr data-index="' + conditionArray.length + '" class="">\n' +
                                        '<td data-field="field" data-key="5-0-0" style="width:110px" align="center" class="">\n' +
                                        '<div class="layui-table-cell laytable-cell-5-0-0" style="width:110px;white-space: nowrap;overflow: hidden !important;text-overflow: ellipsis;">' + result[a].field + '</div>\n' +
                                        '</td>\n' +
                                        '<td data-field="conditionSelect" data-key="5-0-1" align="center" style="width:130px" data-content="" class="layui-table-col-special">\n' +
                                        '<div class="layui-table-cell laytable-cell-5-0-1" style="width:130px;">  \n' +
                                        '<select name="selectValue" lay-filter="selectValue" id="' + result[a].field + '"> \n' +
                                        option +
                                        '</select>\n' +
                                        '<div class="layui-unselect layui-form-select">\n' +
                                        '<div class="layui-select-title">\n' +
                                        '<input type="text" placeholder="请选择" value="等于" readonly="" class="layui-input layui-unselect">\n' +
                                        '<i class="layui-edge"></i>\n' +
                                        '</div>\n' +
                                        '<dl class="layui-anim layui-anim-upbit">\n' +
                                        optionDD +
                                        '</dl>\n' +
                                        '</div>  \n' +
                                        '</div>\n' +
                                        '</td>\n' +
                                        '<td data-field="comment" data-key="5-0-2" style="width:110px" align="center" class="">\n' +
                                        '<div class="layui-table-cell laytable-cell-5-0-2" style="width:110px;white-space: nowrap;overflow: hidden !important;text-overflow: ellipsis;">' + result[a].comment + '</div>\n' +
                                        '</td>\n' +
                                        '<td data-field="dbType" data-key="5-0-3" align="center" class="layui-hide">\n' +
                                        '<div class="layui-table-cell laytable-cell-5-0-3">' + result[a].dbType + '</div>\n' +
                                        '</td>\n' +
                                        '<td data-field="style" data-key="5-0-4" style="width：205px" data-content="" class="layui-table-col-special">\n' +
                                        '<div class="layui-table-cell laytable-cell-5-0-4" style="width:205px">\n' +
                                        '<div class="displayCol"> \n' +
                                        '<select class="layui-yonyou-select rightSelect" lay-filter="valueType" name="rightSelect" id="default' + result[a].field + '"> \n' +
                                        '<option value="1">表单输入</option> \n' +
                                        '<option value="2">固定值</option> \n' +
                                        '<option value="3">脚本</option> \n' +
                                        '<option value="4">动态传入</option> \n' +
                                        '</select>\n' +
                                        '<div class="layui-unselect layui-form-select">\n' +
                                        '<div class="layui-select-title">\n' +
                                        '<input type="text" placeholder="请选择" value="表单输入" readonly="" class="layui-input layui-unselect">\n' +
                                        '<i class="layui-edge"></i>\n' +
                                        '</div>\n' +
                                        '<dl class="layui-anim layui-anim-upbit">\n' +
                                        '<dd lay-value="1" class="">表单输入</dd>\n' +
                                        '<dd lay-value="4" class="">动态传入</dd>\n' +
                                        '<dd lay-value="2" class="">固定值</dd>\n' +
                                        '<dd lay-value="3" class="">脚本</dd>\n' +
                                        '</dl>\n' +
                                        '</div> \n' +
                                        '</div> \n' +
                                        '<div class="userType" style="display:none"> \n' +
                                        '<select class="layui-yonyou-select rightSelect" lay-filter="userType" name="userType" class="userType" id="default' + result[a].field + '"> \n' +
                                        '<option value="1">单行文本框</option>' +
                                        '<option value="4">人员选择器(单选)</option>' +
                                        '<option value="17">角色选择器(单选)</option>' +
                                        '<option value="18">组织选择器(单选)</option>' +
                                        '<option value="19">岗位选择器(单选)</option>' +
                                        ' <option value="0">自定义对话框</option>' +
                                        '</select>\n' +
                                        '<div class="layui-unselect layui-form-select">\n' +
                                        '<div class="layui-select-title">\n' +
                                        '<input type="text" placeholder="请选择" value="单行文本框" readonly="" class="layui-input layui-unselect">\n' +
                                        '<i class="layui-edge"></i>\n' +
                                        '</div>\n' +
                                        '<dl class="layui-anim layui-anim-upbit" style="">' +
                                        '<dd lay-value="1" class="layui-this">单行文本框</dd>' +
                                        '<dd lay-value="4" class="">人员选择器(单选)</dd>' +
                                        '<dd lay-value="17" class="">角色选择器(单选) </dd>' +
                                        '<dd lay-value="18" class="">组织选择器(单选)</dd>' +
                                        '<dd lay-value="19" class="">岗位选择器(单选)</dd>' +
                                        '<dd lay-value="0" class="">自定义对话框</dd></dl>' +
                                        '</div> \n' +
                                        '</div> \n' +
                                        '<div class="dataType" style="display:none">' +
                                        '<select name="formDialog" class="formDialog" lay-filter="formDialog">' +
                                        '<option value=""></option>' +
                                        ' </select>' +
                                        ' <select name="listDialog" class="listDialog" lay-filter="listDialog">' +
                                        '<option value=""></option>' +
                                        '</select>' +
                                        ' </div>' +
                                        '</div>\n' +
                                        '</td>\n' +
                                        '<td data-field="operation" data-key="5-0-5" style="width:160px" align="center" data-off="true" class="">\n' +
                                        '<div class="layui-table-cell laytable-cell-5-0-5" style="width:160px"> \n' +
                                        '<a class="layui-btn layui-btn-xs" lay-event="moveUp">上移</a> \n' +
                                        '<a class="layui-btn layui-btn-xs" lay-event="moveDown">下移</a> \n' +
                                        '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a> \n' +
                                        '</div>\n' +
                                        '</td>\n' +
                                        '</tr>');
                                    if (result[a].dbType != "date") {
                                        $(".userType").css("display", "block");
                                    }
                                    selectData();
                                    form.render();
                                } else {
                                    $("#selectCondition").next().find("tbody").append(
                                        '<tr data-index="' + conditionArray.length + '" class="">\n' +
                                        '<td data-field="field" data-key="5-0-0" style="width:110px" align="center" class="">\n' +
                                        '<div class="layui-table-cell laytable-cell-5-0-0" style="width:110px;white-space: nowrap;overflow: hidden !important;text-overflow: ellipsis;">' + result[a].field + '</div>\n' +
                                        '</td>\n' +
                                        '<td data-field="conditionSelect" data-key="5-0-1" align="center" style="width:130px" data-content="" class="layui-table-col-special">\n' +
                                        '<div class="layui-table-cell laytable-cell-5-0-1" style="width:130px;">  \n' +
                                        '<select name="selectValue" lay-filter="selectValue" id="' + result[a].field + '"> \n' +
                                        '<option value="=">等于</option> \n' +
                                        '<option value="like">LIKE</option> \n' +
                                        '<option value="likeEnd">LIKEEND</option> \n' +
                                        '</select>\n' +
                                        '<div class="layui-unselect layui-form-select">\n' +
                                        '<div class="layui-select-title">\n' +
                                        '<input type="text" placeholder="请选择" value="等于" readonly="" class="layui-input layui-unselect">\n' +
                                        '<i class="layui-edge"></i>\n' +
                                        '</div>\n' +
                                        '<dl class="layui-anim layui-anim-upbit">\n' +
                                        '<dd lay-value="=" class="layui-this">等于</dd>\n' +
                                        '<dd lay-value="like" class="">LIKE</dd>\n' +
                                        '<dd lay-value="likeEnd" class="">LIKEEND</dd>\n' +
                                        '</dl>\n' +
                                        '</div>  \n' +
                                        '</div>\n' +
                                        '</td>\n' +
                                        '<td data-field="comment" data-key="5-0-2" style="width:110px" align="center" class="">\n' +
                                        '<div class="layui-table-cell laytable-cell-5-0-2" style="width:110px;white-space: nowrap;overflow: hidden !important;text-overflow: ellipsis;">' + result[a].comment + '</div>\n' +
                                        '</td>\n' +
                                        '<td data-field="dbType" data-key="5-0-3" align="center" class="layui-hide">\n' +
                                        '<div class="layui-table-cell laytable-cell-5-0-3">' + result[a].dbType + '</div>\n' +
                                        '</td>\n' +
                                        '<td data-field="style" data-key="5-0-4" style="width：205px" data-content="" class="layui-table-col-special">\n' +
                                        '<div class="layui-table-cell laytable-cell-5-0-4" style="width:205px">\n' +
                                        '<div class="displayCol"> \n' +
                                        '<select class="layui-yonyou-select rightSelect" lay-filter="valueType" name="rightSelect" id="default' + result[a].field + '"> \n' +
                                        '<option value="4">动态传入</option> \n' +
                                        '<option value="2">固定值</option> \n' +
                                        '<option value="3">脚本</option> \n' +
                                        '</select>\n' +
                                        '<div class="layui-unselect layui-form-select">\n' +
                                        '<div class="layui-select-title">\n' +
                                        '<input type="text" placeholder="请选择" value="参数传入" readonly="" class="layui-input layui-unselect">\n' +
                                        '<i class="layui-edge"></i>\n' +
                                        '</div>\n' +
                                        '<dl class="layui-anim layui-anim-upbit">\n' +
                                        '<dd lay-value="4" class="">动态传入</dd>\n' +
                                        '<dd lay-value="2" class="">固定值</dd>\n' +
                                        '<dd lay-value="3" class="">脚本</dd>\n' +
                                        '</dl>\n' +
                                        '</div> \n' +
                                        '</div> \n' +
                                        '<td data-field="operation" data-key="5-0-5" style="width:160px" align="center" data-off="true" class="">\n' +
                                        '<div class="layui-table-cell laytable-cell-5-0-5" style="width:160px"> \n' +
                                        '<a class="layui-btn layui-btn-xs" lay-event="moveUp">上移</a> \n' +
                                        '<a class="layui-btn layui-btn-xs" lay-event="moveDown">下移</a> \n' +
                                        '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a> \n' +
                                        '</div>\n' +
                                        '</td>\n' +
                                        '</tr>');
                                    form.render();
                                }
                            }
                        }
                        //3.穿梭到-返回字段
                        if ($(".return").hasClass("layui-show")) {
                            returnAndDisplayField(result, $("#returnField"));
                        }

                        //4.穿梭到-排序字段
                        if ($(".sort").hasClass("layui-show")) {
                            for (var h = 0; h < result.length; h++) {
                                var sortArray = $("#sortField").next().find("tbody").children();
                                //如果条件选择中已经有了相同的则跳过
                                var judge = false;
                                for (var b = 0; b < sortArray.length; b++) {
                                    if ($($(sortArray[b]).get(0)).find("div").html() === result[h].field) {
                                        judge = true;
                                    }
                                }
                                if (judge) {
                                    continue;
                                }
                                $("#sortField").next().find("div .layui-none").remove();//去掉 无数据三个字
                                $("#sortField").next().find("tbody").append(
                                    '<tr data-index="' + sortArray.length + '" class="">\n' +
                                    '<td data-field="field" data-key="5-0-0" style="width: 260px" align="center" class="">\n' +
                                    '<div class="layui-table-cell laytable-cell-5-0-0" style="width: 260px">' + result[h].field + '</div>\n' +
                                    '</td>\n' +
                                    '<td data-field="comment" data-key="5-0-1" style="width: 260px" align="center" data-content="' + result[h].comment + '" class="">\n' +
                                    '<div class="layui-table-cell laytable-cell-5-0-1" style="width: 260px">\n' +
                                    '<input type="checkbox" lay-skin="primary" title="升序(不勾选则为降序)" id="checkbox' + result[h].field + '">\n' +
                                    '<div class="layui-unselect layui-form-checkbox" lay-skin="primary">\n' +
                                    '<span>升序(不勾选则为降序)</span>\n' +
                                    '<i class="layui-icon layui-icon-ok"></i>\n' +
                                    '</div>\n' +
                                    '</div>\n' +
                                    '</td>\n' +
                                    '<td data-field="operation" data-key="5-0-2" style="width: 234px" align="center" data-off="true" class="">\n' +
                                    '<div class="layui-table-cell laytable-cell-5-0-2" style="width: 234px"> \n' +
                                    '<a class="layui-btn layui-btn-xs" lay-event="moveUp">上移</a> \n' +
                                    '<a class="layui-btn layui-btn-xs" lay-event="moveDown">下移</a> \n' +
                                    '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a> \n' +
                                    '</div>\n' +
                                    '</td>\n' +
                                    '</tr>');
                                form.render();
                            }
                        }
                        break;
                }
            });

            //加载条件选择表格
            function loadConditionField(data) {
                table.render({
                    elem: '#selectCondition'
                    , data: data
                    , title: '条件选择'
                    , height: 'full-360'
                    , cols: [[
                        {field: 'field', title: '字段名', width: 110, align: 'center'}
                        , {title: '条件', field: "conditionSelect", width: 130, align: 'center', templet: '#selectType'}
                        , {field: 'comment', title: '显示名', width: 110, align: 'center'}
                        , {field: 'dbType', title: '字段类型', align: 'center', hide: true}
                        , {field: 'style', title: '默认值', width: 205, templet: '#DefaultSelect'}
                        , {field: 'operation', toolbar: '#manageBar', width: 160, title: '管理', align: 'center'}
                    ]]
                    , page: false
                    , limit: 1000
                    , done: function (res, curr, count) {
                        selectData();
                        // 循环表格中每一行
                        $.each(res.data, function (i, item) {
                            //select回显
                            $("#" + res.data[i].field).val(res.data[i].condition);
                            $("#default" + res.data[i].field).val(res.data[i].defaultType);
                            if (res.data[i].defaultType != "1") {
                                $("#default" + res.data[i].field).parent().next().css('display', "none");
                            }
                            if (res.data[i].defaultType === "2") { //固定值
                                $("#default" + res.data[i].field).parent().append("<div style='margin-top:10px;' class='selectorDiv'>" +
                                    "<input type='text'class='layui-input' style='float: left;height: 30px;margin-right:5px;width: 150px' value='" + res.data[i].defaultValue + "'>" +
                                    "</div>");
                            } else if (res.data[i].defaultType === "3") { //脚本
                                $("#default" + res.data[i].field).parent().append("<div style='margin-top:10px;' class='selectorDiv'>" +
                                    "<textarea class='layui-input' style='float: left;height: 70px;width: 150px;margin-right:5px;'>" + res.data[i].defaultValue + "</textarea>" +
                                    "<button type='button' class='layui-btn layui-btn-xs selectScript'>选择</button>" +
                                    "</div>");
                            } else if (res.data[i].defaultType === "1") { //表单输入
                                if (res.data[i].dbType === 'date') {
                                    $("#default" + res.data[i].field).parent().next().css('display', "none");
                                } else {
                                    var childs = $("#default" + res.data[i].field).parent().next().children();
                                    var paraCt = res.data[i].paraCt;
                                    $(childs[0]).val(paraCt);
                                    if (paraCt === '0') {
                                        var dataTypeObject = $("#default" + res.data[i].field).parent().next().next();
                                        dataTypeObject.css('display', "block");
                                        var dataTypeObjectChilds = dataTypeObject.children();
                                        $(dataTypeObjectChilds[0]).val(res.data[i].dialog);
                                        var obj = $(dataTypeObjectChilds[2]);
                                        $.each(allDialogReturn, function (index, objVal) {
                                            if (res.data[i].dialog == objVal.alias) {
                                                var resultArray = JSON.parse(objVal.resultfield);
                                                obj.html("");
                                                obj.append("<option value=''>请选择返回值</option>");
                                                $.each(resultArray, function (index, resultVal) {
                                                    obj.append("<option value=" + resultVal.field + ">" + resultVal.comment + "</option>");
                                                });
                                            }
                                        });
                                        $(obj).val(res.data[i].param);
                                    }
                                }
                            }
                        });
                        var that = this;
                        that.elem.next().find('td[data-field="field"]').css("color", "#red");
                        form.render('select');
                    }
                });
            }

            //显示的字段空表格
            function loadDisplayField(data) {
                if (showStyle == 0) {
                    $('.treeDisplayField').hide();
                    table.render({
                        elem: '#showField'
                        , data: data
                        , title: '显示的字段'
                        , height: 'full-300'
                        , cols: [[
                            {field: 'field', title: '字段名', width: 260, align: 'center'}
                            , {field: 'comment', title: '显示名', width: 260, align: 'center'}
                            , {field: 'operation', toolbar: '#manageBar', width: 234, title: '管理', align: 'center'}
                        ]]
                    });
                } else if (showStyle == 1) { //树形展示
                    $('.listDisplayField').hide();
                    if (JSON.stringify(data) != '[]') {
                        var jsonObject = JSON.parse(data);
                        $("#treeId").val(jsonObject.id);
                        $("#pid").val(jsonObject.pid);
                        $("#pvalue").val(jsonObject.pvalue);
                        $("#displayName").val(jsonObject.displayName);
                        $("#isScript").prop("checked", false);
                        if (jsonObject.isScript == "true") {
                            $("#isScript").prop("checked", true);
                        }
                        form.render("checkbox");
                    }
                }
            }

            //加载返回字段表格
            function loadReturnField(data) {
                table.render({
                    elem: '#returnField'
                    , data: data
                    , title: '返回字段'
                    , height: 'full-300'
                    , cols: [[
                        {field: 'field', title: '字段名', width: 260, align: 'center'}
                        , {field: 'comment', title: '显示名', width: 260, align: 'center'}
                        , {field: 'operation', toolbar: '#manageBar', width: 234, title: '管理', align: 'center'}
                    ]]
                    , page: false
                    , limit: 1000
                });
            }

            //加载排序字段表格
            function loadSortField(data) {
                table.render({
                    elem: '#sortField'
                    , data: data
                    , title: '排序字段'
                    , height: 'full-300'
                    , cols: [[
                        {field: 'field', title: '字段名', width: 260, align: 'center'}
                        , {
                            field: 'comment', title: '排序', width: 260, align: 'center'
                            , templet: function (d) {
                                return '<input type="checkbox" lay-skin="primary" title="升序(不勾选则为降序)" id="checkbox' + d.field + '"/>'

                            }
                        }
                        , {field: 'operation', toolbar: '#manageBar', width: 234, title: '管理', align: 'center'}
                    ]]
                    , page: false
                    , limit: 1000
                    , done: function (res, curr, count) {
                        // 循环表格中每一行
                        $.each(res.data, function (i, item) {
                            //checkbox回显
                            $("#checkbox" + res.data[i].field).prop("checked", res.data[i].comment == "ASC" ? true : false);
                        });
                        form.render('checkbox');
                    }
                });
            }

            function upDownDel(data_tr, obj) {
                switch (obj.event) {
                    case 'moveUp':
                        var tr = $(data_tr).parent().parent().parent();
                        $(tr).insertBefore($(tr).prev());
                        break;
                    case 'moveDown':
                        var tr = $(data_tr).parent().parent().parent();
                        $(tr).insertAfter($(tr).next());
                        break;
                    case 'del':
                        parent.layer.confirm('确定删除当前数据吗？', {
                            btn: ['确定', '取消'] //按钮
                        }, function (index) {
                            var delObj = obj.data;
                            obj.del();
                            parent.layer.close(index);
                        });
                        break;
                }
            }

            //监听显示字段选择行工具
            table.on('tool(showField)', function (obj) {
                var data_tr = $(this);
                upDownDel(data_tr, obj);
            });
            //监听条件选择行工具
            table.on('tool(selectCondition)', function (obj) {
                var data_tr = $(this);
                upDownDel(data_tr, obj);
            });

            //监听返回字段行工具
            table.on('tool(returnField)', function (obj) {
                var data_tr = $(this);
                upDownDel(data_tr, obj);
            });
            //监听排序行工具
            table.on('tool(sortField)', function (obj) {
                var data_tr = $(this);
                upDownDel(data_tr, obj);
            });
        });

        //删除前面的元素
        function deletePrevious(ele) {
            $(ele).prev().remove();
            $(ele).remove();
        }

        //在textarea中添加字段
        function addField(ele) {
            $("#javaScript").insertAtCaret($(ele).text());
        }

        //在光标处插入数据
        $.fn.extend({
            insertAtCaret: function (myValue) {
                var $t = $(this)[0];
                if (document.selection) {
                    this.focus();
                    sel = document.selection.createRange();
                    sel.text = myValue;
                    this.focus();
                } else if ($t.selectionStart || $t.selectionStart == '0') {
                    var startPos = $t.selectionStart;
                    var endPos = $t.selectionEnd;
                    var scrollTop = $t.scrollTop;
                    $t.value = $t.value.substring(0, startPos) + myValue + $t.value.substring(endPos, $t.value.length);
                    this.focus();
                    $t.selectionStart = startPos + myValue.length;
                    $t.selectionEnd = startPos + myValue.length;
                    $t.scrollTop = scrollTop;
                } else {
                    this.value += myValue;
                    this.focus();
                }
            }
        })
    </script>
    <style>
        .layui-colla-content {
            background: #fff;
        }

        .layui-table-tool {
            max-width: 1px;
            z-index: 1;
            position: absolute;
            top: -72px;
        }

        #sortCheck .layui-table-cell .layui-form-checkbox[lay-skin=primary] {
            padding-left: 28px;
        }

        td[data-field='style'] .layui-table-cell, td[data-field='conditionSelect'] .layui-table-cell {
            overflow: visible !important;
            height: auto;
        }

        .conditionTab .layui-table-body {
            overflow: visible !important;
        }

        .conditionTab .layui-table-box, layui-table-view {
            overflow: visible !important;
        }

        #LAY_app {
            overflow: hidden;
        }

        .ccpui-trees .layui-table, .layui-table-view {
            height: auto !important;
        }
    </style>
    </body>
</html>